﻿
var format1 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null) {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='StudentName' size='50' maxlength='50' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='StudentName' size='50' maxlength='50' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='StudentName' size='50' maxlength='50' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' name='StudentName' size='50' maxlength='50' style='width:95%;'>";
        }
    }
}
var format2 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' size='18' maxlength='18' name='IDCard' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' size='18' maxlength='18' name='IDCard' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' size='18' maxlength='18' name='IDCard' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' size='18' maxlength='18' name='IDCard' style='width:95%;'>";
        }
    }
}
var format3 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
        str1.push("<select id='" + id + "' disabled='disabled' name='Sex' style='width:95%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='Sex' style='width:95%;'>");
    }
    str1.push("<option value='00'> </option>");
    if (sData == "" || sData == null) {
        str1.push("<option value='男'>男</option>");
        str1.push("<option value='女'>女</option>");
    } else {
        if (sData == "男") {
            str1.push("<option value='男' selected>男</option>");
            str1.push("<option value='女'>女</option>");
        } else {
            str1.push("<option value='女' selected>女</option>");
            str1.push("<option value='男'>男</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format4 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null) {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='Post' size='10' maxlength='10' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='Post' size='10' maxlength='10' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='Post' size='10' maxlength='10' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' name='Post' size='10' maxlength='10' style='width:95%;'>";
        }
    }
}
var format5 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
        str1.push("<select id='" + id + "' disabled='disabled' name='IsDecision' style='width:70px;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='IsDecision' style='width:70px;'>");
    }
    str1.push("<option value='00'> </option>");
    if (sData == "" || sData == null) {
        str1.push("<option value='1'>是</option>");
        str1.push("<option value='0'>否</option>");
    } else {
        if (sData == "1") {
            str1.push("<option value='1' selected>是</option>");
            str1.push("<option value='0'>否</option>");
        } else {
            str1.push("<option value='0' selected>否</option>");
            str1.push("<option value='1'>是</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format6 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null) {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" title=\"请输入如：2013-01-01的格式\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' size='10' maxlength='10' name='ArriveatTime' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" title=\"请输入如：2013-01-01的格式\" value=\"\" onchange='ChangeEvent1(this);' size='10' maxlength='10' name='ArriveatTime' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" title=\"请输入如：2013-01-01的格式\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' size='10' maxlength='10' name='ArriveatTime' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" title=\"请输入如：2013-01-01的格式\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' size='10' maxlength='10' name='ArriveatTime' style='width:95%;'>";
        }
    }
}
var format7 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
        str1.push("<select id='" + id + "' disabled='disabled' name='HouseType' style='width:100%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='HouseType' style='width:100%;'>");
    }
    str1.push("<option value='00'> </option>");
    for (var i = 0; i < HouseType.length; i++) {
        if (HouseType[i].PhraseID == sData) {
            str1.push("<option value='" + HouseType[i].PhraseID + "' selected>" + HouseType[i].PhraseText + "</option>");
        } else {
            str1.push("<option value='" + HouseType[i].PhraseID + "'>" + HouseType[i].PhraseText + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format8 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
        str1.push("<select id='" + id + "' disabled='disabled' name='TrafficType' style='width:100%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='TrafficType' style='width:100%;'>");
    }
    str1.push("<option value='00'> </option>");
    for (var i = 0; i < TrafficType.length; i++) {
        if (TrafficType[i].PhraseID == sData) {
            str1.push("<option value='" + TrafficType[i].PhraseID + "' selected>" + TrafficType[i].PhraseText + "</option>");
        } else {
            str1.push("<option value='" + TrafficType[i].PhraseID + "'>" + TrafficType[i].PhraseText + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format9 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='Stature' size='20' maxlength='20' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='Stature' size='20' maxlength='20' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='Stature' size='20' maxlength='20' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' name='Stature' size='20' maxlength='20' style='width:95%;'>";
        }
    }
}
var formatStudentState = function (elCell, oRecord, oColumn, sData) {
    var vsData = "";
    if ($('#DliverState').val() == '73DAC2CE-F4BF-403C-9ACC-D075551E3328' || $('#DliverState').val() == '73dac2ce-f4bf-403c-9acc-d075551e3328') {
        vsData = "待确认";
    } else{
        if (sData == "0") {
            vsData = "学习中";
        } else if (sData == "1") {
            vsData = "合格毕业";
        } else if (sData == "2") {
            vsData = "优秀毕业";
        } else if (sData == "3") {
            vsData = "不合格未毕业";
        } else if (sData == "4") {
            vsData = "转期";
        } else if (sData == "5") {
            vsData = "退学";
        } else {
            vsData = "已确认";
        }
    } 
    elCell.innerHTML = "<input type=\"text\" value=\"" + vsData + "\" title=\"" + vsData + "\" readonly='readonly' name='StudentState' size='20' maxlength='20' style='width:95%;color:red;'>";
}
var format10 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
        str1.push("<select id='" + id + "' disabled='disabled' name='IsSignIn' style='width:95%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='IsSignIn' style='width:95%;'>");
    }
    str1.push("<option value='00'> </option>");
    if (sData == "" || sData == null) {
        str1.push("<option value='1'>是</option>");
        str1.push("<option value='0'>否</option>");
    } else {
        if (sData == "1") {
            str1.push("<option value='1' selected>是</option>");
        } else {
            str1.push("<option value='0' selected>否</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format11 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='Explain' size='100' maxlength='100' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='Explain' size='100' maxlength='100' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='Explain' size='100' maxlength='100' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' name='Explain' size='100' maxlength='100' style='width:95%;'>";
        }
    }
}
var format12 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        elCell.innerHTML = "<input type=\"text\" value=\"\" disabled='disabled' name='IsTrain' style='width:95%; background: #e7eaf4;'>";
    } else {
        if (sData == "0") {
            elCell.innerHTML = "<input type=\"text\" value='否' disabled='disabled' name='IsTrain' style='width:95%; background: #e7eaf4;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value='是' disabled='disabled' name='IsTrain' style='width:95%; background: #e7eaf4;'>";
        }
    }
}
//民族
var formatExp1 = function (elCell, oRecord, oColumn, sData) {  
    if (sData == "" || sData == null || sData == "null") {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='MinZu' size='100' maxlength='100' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='MinZu' size='100' maxlength='100' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='MinZu' size='100' maxlength='100' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' name='MinZu' size='100' maxlength='100' style='width:95%;'>";
        }
    }
//    var str1 = [];
//    var id = "id" + Math.random();
//    str1.push("<option value='00'> </option>");
//    if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
//        str1.push("<select id='" + id + "' disabled='disabled' name='MinZu' style='width:100%;'>");
//    } else {
//        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='MinZu' style='width:100%;'>");
//    }
//    str1.push("<option value='00'> </option>");
//    for (var i = 0; i < MinZu.length; i++) {
//        if (MinZu[i].PhraseID == sData) {
//            str1.push("<option value='" + MinZu[i].PhraseID + "' selected>" + MinZu[i].PhraseValue + "</option>");
//        } else {
//            str1.push("<option value='" + MinZu[i].PhraseID + "'>" + MinZu[i].PhraseValue + "</option>");
//        }
//    }
//    str1.push("</select>");
//    elCell.innerHTML = str1.join("");
}
//生日
var formatExp2 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" readonly='readonly' onchange='ChangeEvent1(this);' name='Age' size='10' maxlength='10' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='Age' size='10' maxlength='10' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='Age' size='10' maxlength='10' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' name='Age' size='10' maxlength='10' style='width:95%;'>";
        }
    }
}
//邮箱
var formatExp3 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" readonly='readonly' onchange='ChangeEvent1(this);' name='YouXiang' size='50' maxlength='50' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='YouXiang' size='50' maxlength='50' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" title=\"" + sData + "\" readonly='readonly' onchange='ChangeEvent1(this);' name='YouXiang' size='50' maxlength='50' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' name='YouXiang' size='50' maxlength='50' style='width:95%;'>";
        }
    }
}
//手机
var formatExp4 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (strOperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" readonly='readonly' onchange='ChangeEvent1(this);' size='12' maxlength='12' name='Tel' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' size='12' maxlength='12' name='Tel' style='width:95%;'>";
        }
    } else {
        if (strView == "check" || strDescript == "qdnx" || strDescript == "nxja") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" readonly='readonly' title=\"" + sData + "\" onchange='ChangeEvent1(this);' size='12' maxlength='12' name='Tel' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" title=\"" + sData + "\" onchange='ChangeEvent1(this);' size='12' maxlength='12' name='Tel' style='width:95%;'>";
        }
    }
}

YAHOO.util.Event.addListener(window, "load", function () {
    BindData();
    hideCol();
});
var BindData = function () {
    YAHOO.example.InlineCellEditing = function () {
        var myColumnDefs1 = [
        { key: "MajorStudentID", label: "MajorStudentID", resizeable: true },
        { key: "StudentName", label: "学员姓名", resizeable: true, formatter: format1, width: 80 ,
            editor:new YAHOO.widget.TextboxCellEditor({disableBtns:true})
        },
        { key: "IDCard", label: "身份证", resizeable: true, formatter: format2, width: 140,
            editor: new YAHOO.widget.TextboxCellEditor({ disableBtns: true })
        },
        { key: "Sex", label: "性别", resizeable: true, formatter: format3, width: 60 },
        { key: "Post", label: "职务", resizeable: true, formatter: format4, width: 80,
            editor: new YAHOO.widget.TextboxCellEditor({ disableBtns: true })
        },
        { key: "IsDecision", label: "是否决策人", resizeable: true, formatter: format5, width: 60 },
        { key: "ArriveatTime", label: "到达日期", resizeable: true, formatter: format6, width: 100,
            editor: new YAHOO.widget.TextboxCellEditor({ disableBtns: true })
        },
        { key: "Age", label: "年龄", resizeable: true, formatter: formatExp2, width: 100,
            editor: new YAHOO.widget.TextboxCellEditor({ validator: YAHOO.widget.DataTable.validateNumber })
        },
        { key: "Tel", label: "手机", resizeable: true, formatter: formatExp4, width: 90,
            editor: new YAHOO.widget.TextboxCellEditor({ disableBtns: true })
        },
        { key: "Stature", label: "身高(CM)", resizeable: true, formatter: format9, width: 80,
        editor: new YAHOO.widget.TextboxCellEditor({ validator: YAHOO.widget.DataTable.validateNumber }) },
        { key: "StudentState", label: "学员状态", resizeable: true, formatter: formatStudentState, width: 80}];
        myDataSource1 = new YAHOO.util.DataSource([{ MajorStudentID: "", StudentName: "", IDCard: "", 
            Sex: "", Post: "", IsDecision: "", ArriveatTime: "",Age: "",  Tel: "" , Stature: ""
        }]);
        myDataSource1.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource1.responseSchema = {
            fields: ["MajorStudentID", "StudentName", "IDCard", "Sex", "Post", "IsDecision",
                "ArriveatTime", "Age", "Tel", "Stature", "StudentState"]
        };
        var myDataTable1 = new YAHOO.widget.ScrollingDataTable("con_1", myColumnDefs1,
                            myDataSource1, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable1 = myDataTable1;
        var i1 = 1,
        bReverseSorted1 = false;
        var trackReverseSorts1 = function (oArg) {
            bReverseSorted1 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        var onEventSaveCellEditor = function (oArgs) {
            //SetValueDate(oArgs.newData);
            setValue1(oArgs.editor._oColumn.key, oArgs.newData);
        }
        var SetValueDate = function (val) {
            var oDT = this,
                oConfig = oDT.get("dateOptionsExtend");
            var newData = YAHOO.util.Date.format(val, oConfig, oConfig.locale);
            setValue1(oArgs.editor._oColumn.key, newData);
        }
        myDataTable1.subscribe("rowMouseoverEvent", myDataTable1.onEventHighlightRow);
        myDataTable1.subscribe("rowMouseoutEvent", myDataTable1.onEventUnhighlightRow);
        myDataTable1.subscribe("cellClickEvent", myDataTable1.onEventShowCellEditor);
        myDataTable1.subscribe("editorSaveEvent", onEventSaveCellEditor);
        myDataTable1.subscribe("rowClickEvent", myDataTable1.onEventSelectRow);
        myDataTable1.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue1();
        return {
            ds: myDataSource1,
            dt: myDataTable1
        };
    } ();
}

var GetFormValue1 = function () {
    for (var i = 0; i < DeliverMajorInfo.length; i++) {
        SetFormValue1(DeliverMajorInfo);
    }
}
var SetFormValue1 = function (obj) {
    var arr = eval(obj);
    myDataSource1.liveData = arr;
    mDataTable1.getDataSource().sendRequest(null, { success: mDataTable1.onDataReturnInitializeTable }, mDataTable1);
}

//隐藏/栏位
function hideCol() {
    if (flag == 0) {mDataTable1.hideColumn(parseInt(10)); }
   mDataTable1.hideColumn(parseInt(0)); mDataTable1.refreshView();
}
//值改变事件
var ChangeEvent1 = function (oArgs) {
    var f = oArgs.name;
    var v = oArgs.value.replace(/\s/g, "");
    setValue1(f, v);
}
//f=字段名 v=值
var setValue1 = function (f, v) {
    var recordID = mDataTable1.getSelectedRows()[0];
    var record = mDataTable1.getRecord(recordID);
    record._oData[f] = v;
    if (f == "StudentName") {
        var sTmp;
        for (var i = 0; i < v.length; i++) {
            sTmp = v.substring(i, i + 1);
            if ((v.charCodeAt(i) > 96 && v.charCodeAt(i) < 123) || (v.charCodeAt(i) > 64 && v.charCodeAt(i) < 91) || (v.charCodeAt(i) > 256)) {
            } else {
                alert("学员姓名不能包含特殊字符!");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=StudentName]")[0]).val("");
                record._oData["StudentName"] = "";
                return;
            }
        }
    }
    if (f == "IDCard") {
        var num = v;
        var factorArr = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
        var error;
        var varArray = new Array();
        var intValue;
        var lngProduct = 0;
        var intCheckDigit;
        var intStrLen = num.length;
        var idNumber = num;          
        // initialize
        if ((intStrLen != 15) && (intStrLen != 18)) {
            error = "输入身份证号码长度不对！";
            alert(error);
            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
            record._oData["IDCard"] = "";
            return false;
        }
        // check and set value
        for (i = 0; i < intStrLen; i++) {
            varArray[i] = idNumber.charAt(i);
            if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) {
                error = "错误的身份证号码！.";
                alert(error);
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
                record._oData["IDCard"] = "";
                return false;
            } else if (i < 17) {
                varArray[i] = varArray[i] * factorArr[i];
            }
        }
        if (intStrLen == 18) {
            //check date
            var date8 = idNumber.substring(6, 14);
            if (checkDate(date8) == false) {
                error = "身份证中日期信息不正确！";
                alert(error);
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
                record._oData["IDCard"] = "";
                return false;
            }
            // calculate the sum of the products
            for (i = 0; i < 17; i++) {
                lngProduct = lngProduct + varArray[i];
            }
            // calculate the check digit
            intCheckDigit = 12 - lngProduct % 11;
            switch (intCheckDigit) {
                case 10:
                    intCheckDigit = 'X';
                    break;
                case 11:
                    intCheckDigit = 0;
                    break;
                case 12:
                    intCheckDigit = 1;
                    break;
            }
            // check last digit
            if (varArray[17].toUpperCase() != intCheckDigit) {
                //error = "身份证效验位错误!...正确为： " + intCheckDigit + ".";
                error = "身份证输入错误!";
                alert(error);
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
                record._oData["IDCard"] = "";
                return false;
            }
        }
        else { //length is 15
            //check date
            var date6 = idNumber.substring(6, 12);
            if (checkDate(date6) == false) {
                alert("身份证日期信息有误！");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
                record._oData["IDCard"] = "";
                return false;
            }
        }
        return true;
    }
    if (f == "Post") {
        var sTmp;
        for (var i = 0; i < v.length; i++) {
            sTmp = v.substring(i, i + 1);
            if ((v.charCodeAt(i) > 96 && v.charCodeAt(i) < 123) || (v.charCodeAt(i) > 64 && v.charCodeAt(i) < 91) || (v.charCodeAt(i) > 256)) {
            }
            else {
                alert("职务不能包含特殊字符!");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=Post]")[0]).val("");
                record._oData["Post"] = "";
                return;
            }
        }
    }
    if (f == "ArriveatTime") {
        var myDate = new Date();
        var yy = myDate.getYear();
        if (yy < 1900) yy = yy + 1900;
        var MM = myDate.getMonth() + 1;
        if (MM < 10) MM = '0' + MM;
        var dd = myDate.getDate();
        if (dd < 10) dd = '0' + dd;
        var LocalDate = yy + "-" + MM + "-" + dd + "";
        var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
        var r = v.match(reg);
        if (r == null) {
            if (f == "ArriveatTime") {
                alert("到达时间格式不正确!");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ArriveatTime]")[0]).val(LocalDate);
                //$($($(".yui-dt-selected")[0]).find("input[name=ArriveatTime]")[0]).val(LocalDate);
            }
            if (f == "Age") {
                //alert("生日格式不正确!");
                // $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=Age]")[0]).val(LocalDate);
                //$($($(".yui-dt-selected")[0]).find("input[name=ArriveatTime]")[0]).val(LocalDate);
            }
            setValue1(f, LocalDate);
        }
    }
    if (f == "YouXiang") {
        //        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
        //        if (!myreg.test(v)) {
        //            alert("邮箱格式不正确!");
        //            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=YouXiang]")[0]).val("");
        //            record._oData["YouXiang"] = "";
        //        }
    }
    if (f == "Age") {
        if (isNaN(v) || v < 10 || v > 100) {
            alert("请输入有效的年龄范围(10-100)!");
            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=Age]")[0]).val("");
            record._oData["Age"] = "";
        }
    }
    if (f == "Stature") {
        if (isNaN(v) || v < 100 || v > 230) {
            alert("请输入有效的身高范围(100-230)，单位是CM");
            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=Stature]")[0]).val("");
            record._oData["Stature"] = "";
        }
    }
    if (f == "Tel") {
        if (isNaN(v)) {
            alert("手机号必须为数字!");
            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=Tel]")[0]).val("");
            record._oData["Tel"] = "";
        } else {
            var vlength = v.length;
            if (vlength != 11) {
                if (confirm("您确定您输入的手机号长度为 " + vlength + " 位!")) {

                } else {
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=Tel]")[0]).val("");
                    record._oData["Tel"] = "";
                }
                return;
            }
        }
    }
}
var checkDate = function (date) {
    return true;
}
//新增行
var vi = 1;
var handleAdd = function () {    
    var TotalCount = $("#Account").val();
    var TjNum = $("#txtTjNum").val();
    var Count = TotalCount - TjNum;
    if (Count == 0) {       
        alert("此订单提交数达到交付数" + TjNum + "，不能添加!");
        return;
    } else {
        var list = mDataTable1.getRecordSet()._records;
        if (list.length == Count) {
            alert("此订单提交数已达到交付数量,不能添加!");
            return;
        }
         else {
           
             if ($("#txtHaveNum").val() <= list.length) {
                alert("该期人数已达到交付数量最大值,不能添加!");
                return;
            }
            for (var i = 0; i < list.length; i++) {
                if (list[i]._oData.StudentName == "" || list[i]._oData.StudentName == null) {
                    alert("请先填写第" + (i + 1) + "行 学员名称!");
                    return;
                }
                if (list[i]._oData.IDCard == "" || list[i]._oData.IDCard == null) {
                    //alert("请先填写第" + (i + 1) + "行 身份证号!");
                    //return;
                    list[i]._oData.IDCard = "";
                }
                if (list[i]._oData.Sex == "" || list[i]._oData.Sex == "00" || list[i]._oData.Sex == null) {
                    alert("请先填写第" + (i + 1) + "行 性别!");
                    return;
                }
                if (list[i]._oData.Post == "" || list[i]._oData.Post == null) {
                    alert("请先填写第" + (i + 1) + "行 职务!");
                    return;
                }
                if (list[i]._oData.IsDecision == "" || list[i]._oData.IsDecision == "00" || list[i]._oData.IsDecision == null) {
                    alert("请先填写第" + (i + 1) + "行 是否是决策人!");
                    return;
                }
                if (list[i]._oData.ArriveatTime == "" || list[i]._oData.ArriveatTime == null) {
                    alert("请先填写第" + (i + 1) + "行 到达日期!");
                    return;
                }
            }
            mDataTable1.set("sortedBy", null);
            index = mDataTable1.getRecordSet()._records.length;
            var entity = [{ MajorStudentID: "", StudentName: "", IDCard: "",
                Sex: "", Post: "", IsDecision: "", ArriveatTime: "", 
                Age: "", Tel: "", Stature: ""
            }];
            mDataTable1.addRows(entity, index);
            vi++;
        }
    }
}
//删除行
var handleDelete = function () {
    var recordID = mDataTable1.getSelectedRows()[0];
    if (recordID != null && recordID.length != 1) {
        if (mDataTable1.getRecordSet()._records.length == 1) {
            alert("最后一行不能删除!");
            return;
        } else {
            record = mDataTable1.getRecord(recordID);
            var vid = record.getData("MajorStudentID");
            if (flag == "0") {
                mDataTable1.deleteRow(recordID);
                //LoadAccountReceivable();
            } else {
                if (confirm("您确定删除该行吗?")) {
                    var SaveUrl = "../../Extend/AjaxData/CustomOperating.aspx?r=" + Math.random() + "&action=delete&entity=CrmMajorStudentHr&json=&id=" + vid;
                    YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                        success: function (res) {
                            try {
                                var str = res.responseText;
                                if (str == "1") {
                                    mDataTable1.deleteRow(recordID);
                                    alert("删除成功!");
                                }
                                else {
                                    alert(str + "\n" + "数据删除失败!");
                                    return;
                                }
                            } catch (e) {
                            }
                            finally {
                            }
                        },
                        failure: function (error) {
                            alert("数据错误：" + error.statusText);
                        }
                    }, null);
                }
            }
        }
    } else {
        alert("请选中一行后删除！");
    }
}